#include "LoadResource.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
char nnchar[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//int LoadTextureResource::totalnum = SPRITESNUMS+SHADOWSPRITES+RUNMEMBERS+JUMPUPMEMBERS+JUMPDOWNMEMBERS+FALLDOWNMEMBERS+TRACKSPRITESNUMS;
LoadTextureResource * LoadTextureResource::p = NULL;
LoadTextureResource::LoadTextureResource(void)
{
	this->loadBackground();
	this->loadRoles();
	this->loadTracks();
	this->loadAudio();
};


LoadTextureResource::~LoadTextureResource(void)
{
};
LoadTextureResource* LoadTextureResource::getShare(){
	if (p)
	{
		return p;
	} 
	else
	{
		p = new LoadTextureResource();
		return p;
	}
}

void LoadTextureResource::loadBackground()
{
	std::string pathString = "background/";
	std::string pngString=".png";
	std::string cityString = "_city_";
	std::string desertString ="_desert_";
	std::string recourceString;
	for (int i =0;i<DESERTSTART;i++)
	{
		recourceString =pathString+ cityString+nnchar[i]+pngString;
		backgroundTexture[i] = CCTextureCache::sharedTextureCache()->addImage(recourceString.c_str());
		//CCTextureCache::sharedTextureCache()->addImageAsync()
		//CCLOG(recourceString.c_str());
	}
	for (int i = DESERTSTART,j=0;i<SPRITESNUMS;i++,j++)
	{
		recourceString =pathString+ desertString + nnchar[j]+pngString;
		backgroundTexture[i] = CCTextureCache::sharedTextureCache()->addImage(recourceString.c_str());
		//CCLOG(recourceString.c_str());
	}

	std::string cstring = "shadow_";
	for (int i =0;i<SHADOWSPRITES;i++)
	{
		recourceString =pathString+ cstring+nnchar[i]+pngString;
		backgroundShadowTexture[i] = CCTextureCache::sharedTextureCache()->addImage(recourceString.c_str());
	}
}

void LoadTextureResource::loadRoles()
{
	std::string pathString = "roleaction/";
	std::string png = ".png";
	std::string hstring;
	std::string filename;


	hstring = "jumpUp_";
	for( int i=0;i<JUMPUPMEMBERS;i++)
	{		
		filename =pathString+hstring+nnchar[i]+png;
		//CCLog(filename.c_str());
		roleJumpUpTexture[i]= CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
	}

	// jump down image
	hstring = "jumpDown_";
	for( int i=0;i<JUMPDOWNMEMBERS;i++)
	{
		filename =pathString+ hstring+nnchar[i]+png;
		//CCLog(filename.c_str());
		roleJumpDownTexture[i]=CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
	}
	
	hstring = "falldown_";
	for (int i = 0;i<FALLDOWNMEMBERS;i++)
	{		
		filename =pathString+ hstring+nnchar[i]+png;
		roleFallDownTexture[i] =CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
	}

	hstring = "run_";
	for( int i=0;i<RUNMEMBERS;i++)
	{		
		filename =pathString+ hstring+nnchar[i]+png;
		//CCLog(filename.c_str());
		roleRunTexture[i]=CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
	}
}


void LoadTextureResource::loadTracks()
{
	std::string pathString = "track/";
	std::string pngString=".png";
	std::string trackString = "track_";
	std::string recourceString;
	for (int i =0;i<TRACKSPRITESNUMS;i++)
	{
		recourceString =pathString+ trackString+nnchar[i]+pngString;
		trackSprites[i] = CCTextureCache::sharedTextureCache()->addImage(recourceString.c_str());
		trackSprites[i]->setAliasTexParameters();
		//CCLOG(recourceString.c_str());
	}
}

void LoadTextureResource::loadAudio()
{
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(GOLE_EFFECT);
	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(PROP_EFFECT);
}
